# encoding:UTF-8
import threading
import time

__author__ = 'Hope6537'

# 导入socket库:
import socket
# 创建一个socket:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 建立连接:
s.connect(('www.sina.com.cn', 80))
s.send('GET / HTTP/1.1\r\nHost: '
       'www.sina.com.cn\r\nConnection: close\r\n\r\n')
# 定义缓冲区
buffer = []
while True:
    # 每次最多接收1k字节:
    d = s.recv(1024)
    if d:
        buffer.append()
    else:
        break
data = ''.join(buffer)
s.close()

header, html = data.split('\r\n\r\n', 1)
print header
# 把接收的数据写入文件:
with open('sina.html', 'wb') as f:
    f.write(html)

